package newPan3d.content.lightScene
{
	import _Pan3D.display3D.Display3DSprite;
	
	import flash.display3D.Context3D;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Context3DVertexBufferFormat;
	import flash.display3D.IndexBuffer3D;
	import flash.display3D.VertexBuffer3D;
	
	public class LightDisplay3DFrieSprite extends Display3DSprite
	{
		private var timeNum:Number=1;
		private var context3D:Context3D;
		private var vertexBuffer:VertexBuffer3D;
		private var indexBuffer:IndexBuffer3D; 
		public function LightDisplay3DFrieSprite(context:Context3D)
		{
			super(context);
			context3D=context;
			makeMianpianModel();
		}
		override protected function setVa() : void {
			
			context3D.setTextureAt(1, _objData.texture);
			context3D.setVertexBufferAt(0, vertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
			context3D.setVertexBufferAt(1, vertexBuffer, 3, Context3DVertexBufferFormat.FLOAT_3);
			context3D.drawTriangles(indexBuffer, 0, -1);
		}
		private function makeMianpianModel() : void {
			
			var speed : Number = 300;
			var m: Number=1;
			vertexBuffer  = context3D.createVertexBuffer(4, 6);
			vertexBuffer.uploadFromVector(Vector.<Number>(
				[-speed,  0,speed, 0, 0, 1,
					speed, 0,speed, 1/m, 0, 1, 
					speed, 0,-speed, 1/m, 1/m, 1, 
					-speed,0,-speed,  0, 1/m, 1,]), 0, 4);
			var k : Array = [0, 2, 3, 0, 1, 2];
			indexBuffer  = context3D.createIndexBuffer(k.length);
			indexBuffer.uploadFromVector(Vector.<uint>(k), 0, k.length);
		}
		override protected function resetVa() : void {
			_context.setVertexBufferAt(0, null);
			_context.setVertexBufferAt(1, null);
			context3D.setTextureAt(1, null);
		}
		
		override protected function setVc() : void {
			this.updateMatrix();
			_context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 4, modelMatrix, true);
			_timer++;
			if(_timer>20){
				_timer=0;
				_skip=-_skip;
			}
			if(_skip>0){
				_total=(_timer);
			}else{
				_total=(20-_timer);
			}
			_context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, Vector.<Number>([1, 1, 1,_total/20]));

		}
		private var _total:int=0;
		private var _skip:int=1
		private var _timer:int=0;
		
	}
}